import { persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

import { LOAD_SELECTED_PLAYS } from '../actions/PlaysActions';

const initialState = {
    error: null,
    plays: {}
}

const persistConfig = {
    key: 'plays',
    storage,
    whitelist: ['plays'], // place to select which state you want to persist
}

const playsReducer = (state = initialState, action) => {
    switch (action.type) {
        case LOAD_SELECTED_PLAYS:
            return {
                ...state,
                plays: action.data,
            }
        default:
            return {...state};
    }
};

export default persistReducer(persistConfig, playsReducer);